home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
DSAT_ANA
/
DSAT_ANA.C
next >
Wrap
C/C++ Source or Header
|
1988-11-02
|
6KB
|
253 lines
/*
System error alert table analyzer
"DSAT Analyzer.c"
*/
#include "DSAT.h"
/* ----- Globals ------------------------------------------------------- */
TABLE_PTR TablePtr; /* Pointer to current alert table */
long TableSize; /* Size in bytes of current alert table */
TYPE_PTR What; /* Information array associated to table */
int DSAT_id; /* Current id of 'DSAT' resource */
int Proc_id = 0; /* Id for procedure resources */
int Icon_id = 0; /* Id for icon resources */
/* ----- Set definition type ------------------------------------------- */
static int Definition;
static int Stamp;
int Pass_Stamp(i, p)
int i;
DEFINITION_PTR p;
{
if (p->u.id != Definition)
return 0;
if (What[i].type == type_unknown) {
What[i].type = Stamp;
return 1;
}
return 0;
}
void FindandStamp(id, type)
int id;
int type;
{
Definition = id;
Stamp = type;
ScanTable(TablePtr, TableSize, &Pass_Stamp);
}
/* ----- Find alert definitions ---------------------------------------- */
int Pass_Alerts1(i, p)
int i;
DEFINITION_PTR p;
{
What[i].type = (p->u.length == 10) ? type_alert : type_unknown;
What[i].flag = 0;
What[i].definition = p;
return 0;
}
/* ----- Explore alert definitions ------------------------------------- */
int Pass_Alerts2(i, p)
int i;
DEFINITION_PTR p;
{
if (What[i].type != type_alert)
return 0;
FindandStamp(p->a.text1, type_text);
FindandStamp(p->a.text2, type_text);
FindandStamp(p->a.icon, type_icon);
FindandStamp(p->a.code, type_code);
FindandStamp(p->a.button, type_button);
return 0;
}
/* ----- Explore button definitions ------------------------------------ */
int Pass_Buttons1(i, p)
int i;
DEFINITION_PTR p;
{
register int j, n;
if (What[i].type != type_button)
return 0;
n = p->b.buttons;
for (j = 0; j < n; j++) {
FindandStamp(p->b.button[j].string, type_string);
FindandStamp(p->b.button[j].code, type_code);
}
return 0;
}
/* ----- Find resume buttons ------------------------------------------- */
int Pass_Buttons2(i, p)
int i;
DEFINITION_PTR p;
{
if (What[i].type != type_button)
return 0;
FindandStamp(p->b.id + 1, type_button);
return 0;
}
/* ----- Print detail about each definition ---------------------------- */
static char *Types[] = {
"? ", "ALERT ", "TEXT ", "ICON ",
"BUTTON", "STRING", "CODE "
};
void Detail(i)
register int i;
{
register DEFINITION_PTR p;
register int j, n;
register char line[256];
p = What[i].definition;
switch(What[i].type) {
case type_alert:
sprintf(line,
"text=%d text=%d icon=%d code=%d button=%d\r",
p->a.text1, p->a.text2, p->a.icon, p->a.code, p->a.button);
Output(line);
break;
case type_text:
sprintf(line, "point=(%d,%d) \"%s\"\r",
p->t.location.v, p->t.location.h, p->t.text);
Output(line);
break;
case type_icon:
sprintf(line, "DSAT=%d id=%d", DSAT_id, p->i.id);
CtoPstr(line);
OutputResource(p->i.icon, 128L, 'ICON', Icon_id, line);
{
long iconList[64];
BlockMove(p->i.icon, iconList, 128L);
for (j = 32; j < 64; j++)
iconList[j] = -1L;
OutputResource(iconList, 256L, 'ICN#', Icon_id, line);
}
Icon_id++;
sprintf(line, "rect=(%d,%d,%d,%d)\r",
p->i.location.top, p->i.location.left,
p->i.location.bottom, p->i.location.right);
Output(line);
break;
case type_button:
n = p->b.buttons;
sprintf(line, "buttons=%d", n);
Output(line);
for (j = 0; j < n; j++) {
sprintf(line, " string=%d rect=(%d,%d,%d,%d) code=%d",
p->b.button[j].string,
p->b.button[j].location.top,
p->b.button[j].location.left,
p->b.button[j].location.bottom,
p->b.button[j].location.right,
p->b.button[j].code);
Output(line);
}
Output("\r");
break;
case type_string:
n = p->s.length;
BlockMove(p->s.string, line+1, (long)n);
line[0] = '"';
line[n+1] = '"';
line[n+2] = '\r';
line[n+3] = '\0';
Output(line);
break;
case type_code:
sprintf(line, "DSAT=%d id=%d", DSAT_id, p->c.id);
CtoPstr(line);
OutputResource(p->c.code, (long)(p->c.length),
'PROC', Proc_id++, line);
Output("\r");
break;
default:
Output("\r");
break;
}
}
int Pass_Description(i, p)
int i;
DEFINITION_PTR p;
{
char line[256];
sprintf(line, "%2d.%6d (%3d) %s ",
i, p->u.id, p->u.length, Types[What[i].type]);
Output(line);
Detail(i);
return 0;
}
/* ----- main program -------------------------------------------------- */
void main()
{
register int i, k;
register Handle h;
SFReply sfr;
long rType;
Str255 name;
MaxApplZone();
InitGraf(&thePort);
InitFonts();
InitWindows();
InitMenus();
TEInit();
InitDialogs(0L);
FlushEvents(-1, 0);
SFPutFile((80L<<16) + 80L, "\pSave file as:", "\pDSAT list", 0L, &sfr);
if (!sfr.good)
return;
SetCursor(*GetCursor(watchCursor));
if (OutputOpen(sfr.fName, sfr.vRefNum)) {
SysBeep(1);
return;
}
Output("SYSTEM ERROR ALERT TABLES\r");
i = 1;
do
if (h = GetIndResource('DSAT', i)) {
HLock(h);
TablePtr = (TABLE_PTR)(*h);
TableSize = SizeResource(h);
GetResInfo(h, &DSAT_id, &rType, &name);
k = ScanTable(TablePtr, TableSize, 0L);
sprintf(name,
"\r'DSAT' id=%d size=%ld count=%d\r",
DSAT_id, SizeResource(h), k);
Output(name);
if (k > 0 && (What = (TYPE_PTR)NewPtr(k * sizeof(TYPE)))) {
ScanTable(TablePtr, TableSize, &Pass_Alerts1);
ScanTable(TablePtr, TableSize, &Pass_Alerts2);
ScanTable(TablePtr, TableSize, &Pass_Buttons1);
ScanTable(TablePtr, TableSize, &Pass_Buttons2);
ScanTable(TablePtr, TableSize, &Pass_Buttons1);
ScanTable(TablePtr, TableSize, &Pass_Description);
DisposPtr(What);
}
ReleaseResource(h);
i++;
}
while(h);
OutputClose();
}